package kr.co.redcircle.broker.handler.worker;

import kr.co.redcircle.broker.Broker;
import kr.co.redcircle.broker.information.NodeInformation;
import kr.co.redcircle.broker.io.BrokerRequest;
import kr.co.redcircle.broker.io.BrokerResponse;
import kr.co.redcircle.broker.io.IHandler;
import kr.co.redcircle.broker.registry.Registry;
import kr.co.redcircle.broker.utility.JsonUtility;
import net.sf.json.JSONObject;

public class WorkerNodeRegistrationResponseHandler implements IHandler {

	@Override
	public BrokerResponse invoke(String respString) {
		BrokerRequest jObj = JsonUtility.getBrokerRequest(respString);
		Registry.addMonitorNode(jObj);

		JSONObject param = new JSONObject();
		param.put(Broker.TARGET, Broker.ALL);
	
		BrokerRequest request = new BrokerRequest();
		request.put(Broker.FROM, Registry.getCID());
		request.put(Broker.TO, "NAME");
		request.put(Broker.BUSINESS_S, "worker");
		request.put(Broker.METHOD, "getMethodInforamtion");
		request.put(Broker.PARAMETERS, param);

		NodeInformation nameNode = Registry.getNodeInformation(Broker.BROKER_NAMENODE_INFORMATION);
		
		System.out.println("WorkerNodeBusinessRegistrationResponseHandler.jObj : " + jObj.toString());

		Registry.sendUnicast(nameNode, request);


		return null;
	}

}
